﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
  <head>
    <link rel="stylesheet" href="${ctx}/common/common.css" />
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all" />
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
  </head>
  <body>
    <!--主体内容层-->
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15 layui-form">
          <form>
            <!--输入框内容盒子-->
            <div class="layui-col-md12" style="display: flex; align-items: center">
              <div class="layui-col-md8" style="width: 80%">
                <label class="layui-form-label">生产企业</label>
                <!--输入框-->
                <div class="layui-input-block">
                  <input
                    type="text"
                    name="productionName"
                    id="productionName"
                    placeholder="请输入生产企业名称"
                    class="layui-input"
                  />
                </div>
              </div>
              <div class="layui-col-md3" style="width: 20%; text-align: center">
                <div class="layui-btn-group paramBtn">
                  <button id="companyButton" type="button" class="layui-btn layui-btn-sm layui-btn-danger">查询</button>
                  <button type="reset" id="resetCompany" class="layui-btn layui-btn-sm layui-btn-danger">重置</button>
                </div>
              </div>
            </div>
          </form>
          <table
            class="layui-table demo"
            lay-data="{ url:'${ctx}/productionDetection/queryEnterpriseAllPage?companyIds=${companyIds}', page:false ,groups:5,id:'demo'}"
            lay-filter="demo"
          >
            <thead>
              <tr>
                <!-- <th lay-data="{radio:true}" class="radioTh"></th> -->
                <th lay-data="{field:'right',toolbar:'#barDemo',templet:'#selectedOne'}">操作</th>
                <th lay-data="{field:'name',sort:true,event:'check'}">企业名称</th>
              </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="selectOne">选择</a>
    </script>
    <script type="text/html" id="selectedOne">
      {{# if(d.id!='${companyIds}') { }}
      <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="selectOne">未选择1</a>
      {{# } }} {{# if(d.id=='${companyIds}') }}
      <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="selectOne">已选择2</a>
      {{#}}
    </script>
  </body>
  <script>
    var $;
    var companyIds = "";
    var companyNames = "";
    var oldCompanyIds;
    layui.use("table", function () {
      $ = layui.$;
      var loading = layer.msg("数据加载中...");
      var table = layui.table;
      table.render({
        elem: "#demo",
        done: function () {
          layer.close(loading);
          $("#allCheck").remove();
          $("#productionCompanyId").val("");
          $("#companyName").html("");
        },
      });

      table.on("tool(demo)", function (obj) {
        //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        if (layEvent === "selectOne") {
          //点击企业名称
          //复制请求
          $("#productionCompanyId", parent.document).val(data.id);
          $("#companyName", parent.document).html(data.name);
          //联动产品信息
          parent.getProductData(data.id);

          $("#batchCode", parent.document).val("");
          $("#batchId", parent.document).val("");

          parent.emptyDate();
          //关闭窗口
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
        }
      });

      /**
       * 条件查询中的查询按钮
       * */
      $("#resetCompany").on("click", function () {
        //这里以搜索为例
        table.reload("demo", {
          where: {
            //设定异步数据接口的额外参数，任意设
            productionName: "",
          },
          page: {
            curr: 1, //重新从第 1 页开始
          },
        });
      });

      $("#companyButton").on("click", function () {
        table.reload("demo", {
          where: {
            //设定异步数据接口的额外参数，任意设
            productionName: $("#productionName").val(),
          },
          page: {
            curr: 1, //重新从第 1 页开始
          },
        });
      });
    });
  </script>
</html>
